import sys

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget,
                             QPushButton, QPlainTextEdit, QVBoxLayout,
                             QStatusBar)

from utils.MouseMoveFilter import MouseMoveFilter


class DemoEventFilter(QMainWindow):
    def __init__(self, parent=None):
        super(DemoEventFilter, self).__init__(parent)

        self.filter = MouseMoveFilter(self)

        # 设置窗口标题
        self.setWindowTitle('实战PyQt5: 事件过滤器演示')
        # 设置窗口大小
        self.resize(400, 280)

        self.initUi()


    def initUi(self):
        # 状态条
        #self.sBar = QStatusBar(self)
       # self.setStatusBar(self.sBar)

        # 无边框
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setWindowOpacity(0.9)  # 设置窗口透明度
        # self.setAttribute(Qt.WA_TranslucentBackground)  # 设置窗口背景透明


        mainWidget = QWidget()
        mainLayout = QVBoxLayout()

        self.btnSetFilter = QPushButton('安装事件过滤器')
        self.btnMove = QPushButton('长按移动')

        self.onButtonSetFilter()


        self.btnSetFilter.clicked.connect(self.onButtonSetFilter)
        self.textEditor = QPlainTextEdit()

        mainLayout.addWidget(self.btnSetFilter)
        mainLayout.addWidget(self.btnMove)
        mainLayout.addWidget(self.textEditor)

        mainWidget.setLayout(mainLayout)
        self.setCentralWidget(mainWidget)

    def onButtonSetFilter(self):
        self.filter.watch = self.btnMove
        self.btnMove.installEventFilter(self.filter)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = DemoEventFilter()
    window.show()
    sys.exit(app.exec())
